package team.bailan.controller.game;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team.bailan.common.config.ReturnResponse;
import team.bailan.common.process.dealcard.InitialCards;
import team.bailan.common.process.ingame.InGameMap;
import team.bailan.common.process.roblord.RobLordMap;
import team.bailan.common.util.NeedVerify;
import team.bailan.entity.domain.Card;
import team.bailan.entity.dto.CardsInfDTO;
import team.bailan.entity.dto.PlayerPositionDTO;
import team.bailan.entity.dto.RoomInfDTO;
import team.bailan.entity.vo.JudgeCardVO;
import team.bailan.entity.vo.PlayerPositionInfVO;
import team.bailan.service.GameService;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/game")
public class GameController {
    @Autowired
    private GameService gameService;

    @ApiOperation("全局初始化")
    @PostMapping("init")
    public ReturnResponse<String> init(@RequestBody RoomInfDTO roomInfDTO) throws IOException {
        return gameService.init(roomInfDTO);
    }

    @ApiOperation("进入房间")
    @PostMapping("room")
    @NeedVerify
    public ReturnResponse<PlayerPositionInfVO> enterTheRoom(HttpServletRequest request, @RequestBody RoomInfDTO roomInfDTO) {
        return gameService.enterTheRoom(request, roomInfDTO);
    }

    @ApiOperation("玩家准备")
    @PostMapping("preparation")
    public ReturnResponse<String> prepareForGame(@RequestBody PlayerPositionDTO playerPositionDTO) {
        return gameService.prepareForGame(playerPositionDTO);
    }

    @ApiOperation("判断是否能出牌")
    @PostMapping("cards")
    public ReturnResponse<JudgeCardVO> judgePlayCard(@RequestBody CardsInfDTO cardsInfDTO) {
        return gameService.judgePlayCard(cardsInfDTO);
    }

    @ApiOperation("出牌")
    @PostMapping("play")
    public ReturnResponse<String> playCards(@RequestBody CardsInfDTO cardsInfDTO) {
        return gameService.playCards(cardsInfDTO);
    }

    @ApiOperation("不出")
    @PostMapping("not")
    public ReturnResponse<String> doNotPlayCards(@RequestBody RoomInfDTO roomInfDTO) {
        return gameService.doNotPlayCards(roomInfDTO);
    }

    @ApiOperation("测试接口")
    @PostMapping("test")
    public ReturnResponse<Map<String, List<Card>>> getPlayerCards(@RequestBody RoomInfDTO roomInfDTO) {
        return gameService.getPlayerCards(roomInfDTO);
    }
}
